/**
 * Created by Administrator on 2017/9/18/0018.
 */
require.config({
    baseUrl: "script/module"
});
require(["jquery", "webSocketChannel", 'jquery.cookie', 'userHandler', 'm/chatAreaDom', 'chatHandler', 'm/courseInfoDom','m/courseListDom', 'courseViewController', "voteModule"],
    function ($, ws, cookie, userHandler, chatAreaDom, chatHandler, courseInfo,courseList, viewControl, voteModule) {

        // 测试
        // $.cookie("courseId", 2);

        var stuInfo = {
                username: "test2",
                password: "test2"
            },
            tchInfo = {
                username: "gzq9425",
                password: "123"
            }
        //
        // var userHandler = new userHandler.UserHandler();
        // userHandler.login(stuInfo, function () {

            var courseId = $.cookie("courseId");
            var type = $.cookie("type");
            var userHandler = new userHandler.UserHandler();


            // 框架
            var name = document.getElementById('name');
            name.innerHTML = $.cookie("name");
            var logout = document.getElementById('logout');
            logout.addEventListener("clcik",function () {

                userHandler.logout(function () {
                    alert("OK");
                    $.cookie('courseId','',{ expires: 0 });
                    $.cookie('type','',{ expires: 0 });
                    location.reload()
                },function () {
                    alert("注销失败")
                })
            })

            var courseInfoDom = document.getElementById('course-info'),
                courseListDom = document.getElementById('course-list');
            courseInfoDom.addEventListener("click", stateSwitcher);
            courseListDom.addEventListener("click", stateSwitcher);
            function stateSwitcher(e) {
                // 监测是否点击block__title
                var isTitle = false;
                for (var i in e.path) {
                    if (e.path[i] instanceof HTMLElement && e.path[i].classList.contains('block__title')) {
                        isTitle = true;
                        break;
                    }
                }
                if (!isTitle) {
                    return;
                }
                this.classList.toggle('hidden')
            }

            //Page 1
            // 聊天区域
            chatAreaDom.execute();
            setTimeout(function () {


                chatHandler.send({name: "lph", data: "hello, im " + Math.random()}, function () {
                    console.log("sendMedssage");
                }, function () {
                    console.log("妈呀没发出去")
                })
            }, 3000);


            // 课程管理区域
            courseList.execute();

            // 课程介绍区域
            courseInfo.execute();


            //question页面


            function init() {
                viewControl.m_showNotice(courseId);
                viewControl.m_showFile(courseId);


                viewControl.m_studentGetVote(courseId);


            }

            init();

        //
        // })


    })